package controller

import (
	"fx_swift_agent/api"
	"fx_swift_agent/internal/service"
	"fx_swift_agent/pkg/code"
	"fx_swift_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

func IndexOne(c *gin.Context) {
	result, err := service.NewAgentSrv().IndexOne(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func IndexSecond(c *gin.Context) {
	req := &api.IndexSecondReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewAgentSrv().IndexSecond(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func IndexThird(c *gin.Context) {
	result, err := service.NewAgentSrv().IndexThird(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func IndexFour(c *gin.Context) {
	req := &api.IndexFourReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewAgentSrv().IndexFour(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
